#!/usr/bin/python3
# @Time    : 2024-03-22 上午 9:20
# @Author  : MingYangHe
# @Email   : 1780040868@qq.com
from typing import Optional


class ListNode:
    def __init__(self, val=0, next=None):
        self.val = val
        self.next = next

    def getValue(self):
        return self.val

    def getNextValue(self):
        return self.next

    def setValue(self, new_val):
        self.val = new_val

    def setNextValue(self, new_next):
        self.next = new_next


class LinkedList:
    def __init__(self):
        self.head = None

    def append(self, val):
        if not self.head:
            self.head = ListNode(val)
        else:
            current = self.head
            while current.getNextValue():
                current = current.getNextValue()
            current.setNextValue(ListNode(val))

    def printList(self):
        current = self.head
        while current:
            print(current.getValue(), end=" -> ")
            current = current.getNextValue()
        print("None")

class Solution:
    def removeElements(self, head: Optional[ListNode], val: int) -> Optional[ListNode]:
        # 创建虚拟头节点
        dummy_head = ListNode(next=head)
        current = dummy_head
        while current.next:
            if current.next.val == val:
                current.next = current.next.next
            else:
                current = current.next
        return dummy_head.next

# main函数
def main():
    head = [1,2,6,3,4,5,6]
    val = 6

    ll = LinkedList()
    # 输入
    input_values = head
    for val in input_values:
        ll.append(val)

    # 输出
    print("List:")
    ll.printList()
    sou=Solution()

    sou.removeElements(ll.head,val)
    print("List:")
    ll.printList()



if __name__ == '__main__':
    main()